home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AlexNeXTSTEPSource / Source / Chapter6_Events / ControlDemo / Control_1.m next >
Text File  |  1995-06-12  |  1KB  |  59 lines

  1. #import <appkit/appkit.h>
  2.  
  3. // a minimal program to demonstrate how
  4. // to add controls to a window
  5.  
  6. main()
  7. {
  8.     // create an application object
  9.     // to establish connection to
  10.     // Window Server
  11.     id NXApp = [Application new];
  12.     id theWindow;
  13.     id theMenu;
  14.     id theButton;
  15.     NXRect theRect;
  16.  
  17.     // create a window that's at 125, 125
  18.     // and is 200 by 300 pixels
  19.     NXSetRect(&theRect, 125, 125, 200, 300);
  20.     theWindow = [ [Window alloc]
  21.         initContent:&theRect
  22.         style: NX_TITLEDSTYLE
  23.         backing:NX_BUFFERED
  24.         buttonMask:NX_MINIATURIZEBUTTONMASK
  25.         defer:YES];
  26.  
  27.     // create the menu
  28.     theMenu = [ [Menu alloc]
  29.         initTitle: [NXApp appName] ];
  30.     // create the menu option
  31.     [theMenu addItem:"Quit"
  32.         action:@selector(terminate:)
  33.         keyEquivalent:'q'];
  34.  
  35.     // resize menu to accomodate menu option
  36.     [theMenu sizeToFit];
  37.     [NXApp setMainMenu:theMenu];
  38.  
  39.     // create a button that's 80 by 20
  40.     NXSetRect(&theRect, 0, 0, 80, 20);
  41.     theButton = [ [Button alloc]
  42.         initFrame:&theRect];
  43.     // set the title for the button
  44.     [theButton setTitle:"Press Here"];
  45.     // since the button is a view, we need
  46.     // to install it as the subview of the
  47.     // window's contentview or else it
  48.     // won't draw
  49.     [ [theWindow contentView]
  50.         addSubview: theButton];
  51.  
  52.     // send the window to the front
  53.     // and display it
  54.     [theWindow makeKeyAndOrderFront:nil];
  55.  
  56.     // go into event loop to wait for events
  57.     [NXApp run];
  58. }
  59.